package com.eam.asset.file.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.eam.asset.file.vo.AssetLand.AssetLandAddVo;
import com.eam.asset.file.vo.AssetLand.AssetLandPutVo;
import com.eam.asset.file.vo.AssetLand.AssetLandQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.eam.common.annotation.Log;
import com.eam.common.core.controller.BaseController;
import com.eam.common.core.domain.AjaxResult;
import com.eam.common.enums.BusinessType;
import com.eam.asset.file.domain.AssetLand;
import com.eam.asset.file.service.IAssetLandService;
import com.eam.common.utils.poi.ExcelUtil;
import com.eam.common.core.page.TableDataInfo;

/**
 * 土地资产档案Controller
 *
 * @author tzf
 * @date 2023-10-31
 */
@RestController
@RequestMapping("/asset/land")
@Validated
@Api(tags = "土地资产控制器")
public class AssetLandController extends BaseController {
    private final IAssetLandService assetLandService;

    //构造器注入
    @Autowired
    public AssetLandController(IAssetLandService assetLandService) {
        this.assetLandService = assetLandService;
    }

    /**
     * 查询土地资产档案列表
     */
    @PreAuthorize("@ss.hasPermi('asset:land:list')")
    @GetMapping("/list")
    @ApiOperation(value = "获取资产列表")
    public TableDataInfo list(AssetLandQueryVo assetLand) {
        startPage();
        List<AssetLand> list = assetLandService.selectAssetLandList(assetLand);
        return getDataTable(list);
    }

    /**
     * 导出土地资产档案列表
     */
    @PreAuthorize("@ss.hasPermi('asset:land:export')")
    @Log(title = "土地资产档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出Excel")
    public void export(HttpServletResponse response, AssetLandQueryVo assetLand) {
        List<AssetLand> list = assetLandService.selectAssetLandList(assetLand);
        ExcelUtil<AssetLand> util = new ExcelUtil<AssetLand>(AssetLand.class);
        util.exportExcel(response, list, "土地资产档案数据");
    }

    /**
     * 获取土地资产档案详细信息
     */
    @PreAuthorize("@ss.hasPermi('asset:land:query')")
    @GetMapping(value = "/{landId}")
    @ApiOperation(value = "查询土地资产")
    public AjaxResult getInfo(@PathVariable("landId") String landId) {
        return success(assetLandService.selectAssetLandByLandId(landId));
    }

    /**
     * 新增土地资产档案
     */
    @PreAuthorize("@ss.hasPermi('asset:land:add')")
    @Log(title = "土地资产档案", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "添加土地资产")
    public AjaxResult add(@RequestBody AssetLandAddVo assetLand) {
        return toAjax(assetLandService.insertAssetLand(assetLand));
    }

    /**
     * 修改土地资产档案
     */
    @PreAuthorize("@ss.hasPermi('asset:land:edit')")
    @Log(title = "土地资产档案", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改土地资产")
    public AjaxResult edit(@Validated @RequestBody AssetLandPutVo assetLand) {
        return toAjax(assetLandService.updateAssetLand(assetLand));
    }

    /**
     * 删除土地资产档案
     */
    @PreAuthorize("@ss.hasPermi('asset:land:remove')")
    @Log(title = "土地资产档案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{landIds}")
    @ApiOperation(value = "删除土地资产")
    public AjaxResult remove(@PathVariable String[] landIds) {
        return toAjax(assetLandService.deleteAssetLandByLandIds(landIds));
    }
}
